<?php
class Teacher extends CI_Controller {
	private $data;
	public function __construct()
	{
		parent::__construct();
		define('LANGUAGE', 'zh_TW');
		$this->load->model('db_model');
		$this->lang->load("message",LANGUAGE);
		
		$this->data['title'] =  $this->lang->line("title");
		$this->data['footer'] =  $this->lang->line("footer"). $this->lang->line("contact_address") . $this->lang->line("contact_phone");

	}

	public function index()
	{
//		$data['news'] = $this->news_model->get_news();
		$this->load->helper('form');
		$this->load->view('templates/header', $this->data);
		$this->load->library('parser');

$data = array(
              'btnAdd'   => $this->lang->line("btnAdd"),
              'btnSave'   => $this->lang->line("btnSave"),
              'btnDelete'   => $this->lang->line("btnDelete"),
              'lblSkill'   => $this->lang->line("lblSkill")
            );

$this->parser->parse('skill_create', $data);
//		$this->load->view('skill_create');
		$this->load->view('templates/footer', $this->data);
//		echo "123";
	}

	public function view($args)
	{
		$this->data['news_item'] = $this->db_model->get_news($args);
		if (empty($this->data['news_item']))
		{
			show_404();
		}

//		$data['title'] = $data['news_item']['t_id'];

		$this->load->view('templates/header', $this->data);
		$this->load->view('db_view', $this->data);
		$this->load->view('templates/footer', $this->data);
	}

  function list_student()
  {
    $this->load->library('table');
	$this->load->helper('form');
    $students_qry = $this->db_model->listStudents();
    $skill_qry = $this->db_model->getSkill();

	echo form_open('teacher/StudentSkill');
	$txt_str = "<input type='hidden' name='sid[%d]' value='%s'>%s";
	$sel_str = "<select name='skill[%d]'>\n";
	foreach( $skill_qry->result_array() as $item) {
		$sel_str .=  '<option value="' . $item["sk_id"] . '">' .  $item["s_name"] . '</option>\n';
	}
	$sel_str .= "</select>\n";

	$rd_str = '<input type="radio" name="maturity[%d]" value="1" checked>尚可<input type="radio" name="maturity[%d]" value="2">精通';
	
	$this->table->set_heading('姓名', '技能', '精熟程度');
	$i=0;
	foreach( $students_qry->result_array() as $item) {
		$this->table->add_row(sprintf($txt_str,$i,$item["s_id"],$item["s_name"]), sprintf($sel_str,$i), sprintf($rd_str,$i,$i));
		$i++;
	}
	echo $this->table->generate();
	echo '<input type="submit" value="Confirm" id="btnSave">';
	echo form_close();
/*
	print "<pre>";
//    $students_table = $this->table->generate($students_qry);
	var_dump($students_qry->result_array());
	print "</pre>";
*/	
  }
	function StudentSkill() {
		$this->db_model->set_studentskill();
		$this->load->view('success');	
	}
	public function create()
	{
//		$this->load->helper('form');
		$this->db_model->set_skill();
		$this->list_student();
//		$this->load->library('form_validation');

//		$data['title'] = 'Create a teacher';

//		$this->form_validation->set_rules('account', 'Title', 'required');
//		$this->form_validation->set_rules('name', 'Text', 'required');
/*
     print "<pre>";

	 foreach($this->input->post('iptNo') as $day){
		echo $day;
	}
	
//     var_dump($this->input->post('iptNo'));
     print "</pre>";
*/	 
/*
	 if ($this->form_validation->run() === FALSE)
		{
			$this->load->view('templates/header', $this->data);
			$this->load->view('create');
			$this->load->view('templates/footer', $this->data);

		}
		else
		{
			$this->db_model->set_news();
			$this->load->view('success');
		}
*/	
	}
	
}

